package com.onluy.conf;


import com.onluy.conf.interceptor.SysLogsInterceptor;
import com.onluy.frameworkcloud.system.interceptor.ParamCheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 配置静态资源映射
 * @author sam
 * @since 2017/7/16
 */
@Configuration
@Component
public class WebMvcConfig extends WebMvcConfigurerAdapter      /*extends WebMvcConfigurationSupport*/ {

    @Autowired
    private  SysLogsInterceptor sysLogsInterceptor;

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        //将所有/static/** 访问都映射到classpath:/static/ 目录下
        registry.addResourceHandler("/MgrScript/**/*.js").addResourceLocations("classpath:/templates/");
        registry.addResourceHandler("/MgrScript/**/*.css").addResourceLocations("classpath:/templates/");

    }


    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        //参数校验拦截器
        List<String> patterns= new ArrayList<String>();
        patterns.add("/sysmgr/**");
        registry.addInterceptor(new ParamCheckInterceptor())  .addPathPatterns(patterns) ;


        //系统日志拦截器
        List<String> logspatterns= new ArrayList<String>();
        logspatterns.add("/sysmgr/**");
        registry.addInterceptor(sysLogsInterceptor) .addPathPatterns(logspatterns) ;

    }




}